package xiao_jin.fantastic_journey.util;

import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.Box;
import net.minecraft.util.math.Vec3d;
import xiao_jin.fantastic_journey.FantasticJourney;
import xiao_jin.fantastic_journey.api.capability.Capability;
import xiao_jin.fantastic_journey.api.capability.CapabilityManager;
import xiao_jin.fantastic_journey.api.capability.CapabilityPayload;

@SuppressWarnings("unused")
public final class ModUtil {
    public static final ThermiteRandom RANDOM = new ThermiteRandom();

    private ModUtil() {
    }

    public static Box getBoxByRange(Vec3d vec, int range) {
        return new Box(vec.x - range, vec.y - range, vec.z - range, vec.x + range, vec.y + range, vec.z + range);
    }

    public static Identifier getIdOfMod(String path) {
        return Identifier.of(FantasticJourney.MOD_ID, path);
    }

    public static Identifier getIdOf(String domain, String path) {
        return Identifier.of(domain, path);
    }

    public static Text translatable(String name) {
        return Text.translatable(String.format("fantastic_journey.%s", name));
    }

    public static Text translatable(String domain, String name) {
        return Text.translatable(String.format("%s.fantastic_journey.%s", domain, name));
    }

    public static void registerCapability(Identifier id, CapabilityPayload payload, NbtCompound nbtCompound, PlayerEntity player) {
        Capability cap = CapabilityManager.manager().findCapability(id);
        if (cap == null) {
            FantasticJourney.LOGGER.error("A unregister capability in a packet: {}", id);
            return;
        }
        cap.readIn(payload.getNbt());
        cap.writeInto(nbtCompound);
        cap.init();
    }
}
